package com.symbio.ishenapi.background.controller;

import com.jfinal.kit.StrKit;
import com.symbio.ishenapi.background.model.TmDoctorBasic;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Date;

@RequestMapping("BackDoctro")
public class TmBackDoctroController extends BaseController {

    public void saveDoctro(){ //医生基本资料添加

        TmDoctorBasic tmDoctorBasic =(TmDoctorBasic)getReqBodyObject(TmDoctorBasic.class);
       // tmDoctorBasic.setCreateTime(new Date());
        if (tmDoctorBasic.getDoctorName() ==null || "".equals(tmDoctorBasic.getDoctorName())){
            renderJsonError(40003, "医生姓名");
        }else if (tmDoctorBasic.getDoctorSex() ==null || "".equals(tmDoctorBasic.getDoctorSex())){
            renderJsonError(40003, "医生性别");
        }else if (tmDoctorBasic.getDoctorPhone() ==null || "".equals(tmDoctorBasic.getDoctorPhone())){
            renderJsonError(40003, "医生手机号");
        }else if (tmDoctorBasic.getBranch() ==null || "".equals(tmDoctorBasic.getBranch())){
            renderJsonError(40003, "分组");
        }else if (tmDoctorBasic.getDepartmentName() ==null || "".equals(tmDoctorBasic.getDepartmentName())){
            renderJsonError(40003, "科室");
        }else if (tmDoctorBasic.getJobName() ==null || "".equals(tmDoctorBasic.getJobName())){
            renderJsonError(40003, "职称");
        }else if (tmDoctorBasic.getHostptialId() ==null || "".equals(tmDoctorBasic.getHostptialId())){
            renderJsonError(40003, "医院");
        }else if (tmDoctorBasic.getDoctorCard() ==null || "".equals(tmDoctorBasic.getDoctorCard())){
            renderJsonError(40003, "医生身份证号");
        }else if (tmDoctorBasic.getDoctroEmail() ==null || "".equals(tmDoctorBasic.getDoctroEmail())){
            renderJsonError(40003, "医生邮箱");
        }else if (tmDoctorBasic.getProfessionalCode() ==null || "".equals(tmDoctorBasic.getProfessionalCode())){
            renderJsonError(40003, "医生职业编号");
        }else if (tmDoctorBasic.getIntroduce() ==null || "".equals(tmDoctorBasic.getIntroduce())){
            renderJsonError(40003, "医生简介");
        }else if (tmDoctorBasic.getBeGood() ==null || "".equals(tmDoctorBasic.getBeGood())){
            renderJsonError(40003, "擅长");
        }else if (tmDoctorBasic.getCreditNumber() ==null || "".equals(tmDoctorBasic.getCreditNumber())){
            renderJsonError(40003, "银行卡号");
        }else if (tmDoctorBasic.getDepositBank() ==null || "".equals(tmDoctorBasic.getDepositBank())){
            renderJsonError(40003, "开户银行");
        }else if (tmDoctorBasic.getDoctorSex() ==null || "".equals(tmDoctorBasic.getDoctorSex())){
            renderJsonError(40003, "医生性别");
        }else if (tmDoctorBasic.getSeniority() ==null || "".equals(tmDoctorBasic.getSeniority())){
            renderJsonError(40003, "年资");
        }
        else {
            tmDoctorBasic.save();
            renderJsonError(40001,"医生基本信息");
        }
    }

    public void updateDoctro(){

        TmDoctorBasic ts = (TmDoctorBasic) getReqBodyObject(TmDoctorBasic.class);
        TmDoctorBasic byId = TmDoctorBasic.dao.findById(ts.getId());
        System.out.print(byId+"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        if (byId ==null){
            if (!StrKit.isBlank(ts.getId().toString())) byId.setId(ts.getId());
            if (!StrKit.isBlank(ts.getHostptialId().toString())) byId.setHostptialId(ts.getHostptialId());
            if (!StrKit.isBlank(ts.getDoctorName())) byId.setDoctorName(ts.getDoctorName());
            if (!StrKit.isBlank(ts.getDoctorSex())) byId.setDoctorSex(ts.getDoctorSex());
            if (!StrKit.isBlank(ts.getDoctorPhone())) byId.setDoctorPhone(ts.getDoctorPhone());
            if (!StrKit.isBlank(ts.getDoctorCard())) byId.setDoctorCard(ts.getDoctorCard());
            if (!StrKit.isBlank(ts.getDoctroEmail())) byId.setDoctroEmail(ts.getDoctroEmail());
            if (!StrKit.isBlank(ts.getSeniority())) byId.setSeniority(ts.getSeniority());
            if (!StrKit.isBlank(ts.getBranch())) byId.setBranch(ts.getBranch());
            if (!StrKit.isBlank(ts.getDepartmentName())) byId.setDoctorSex(ts.getDepartmentName());
            if (!StrKit.isBlank(ts.getJobName())) byId.setJobName(ts.getJobName());
            if (!StrKit.isBlank(ts.getProfessionalCode())) byId.setProfessionalCode(ts.getProfessionalCode());
            if (!StrKit.isBlank(ts.getIntroduce())) byId.setIntroduce(ts.getIntroduce());
            if (!StrKit.isBlank(ts.getBeGood())) byId.setBeGood(ts.getBeGood());
            if (!StrKit.isBlank(ts.getCreditNumber())) byId.setCreditNumber(ts.getCreditNumber());
            if (!StrKit.isBlank(ts.getDepositBank())) byId.setDepositBank(ts.getDepositBank());
            if (!StrKit.isBlank(ts.getSeniority())) byId.setSeniority(ts.getSeniority());
            if (byId.update()) {
                renderJsonRet(ts.getId());
            } else {
                renderJsonError(40005,"医生基本信息");

            }
        }else{
            renderJsonError(40003,"医生基本信息");
            return;
        }
        }


}
